/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainFrame.java
 *
 * Created on Jun 28, 2009, 3:33:26 PM
 */
package org.dbdir.client.gui;

import org.dbdir.Client;

/**
 *
 * @author thotheolh
 */
public class MainFrame extends javax.swing.JFrame {

    private LoginPane login;
    private GenActionPane action;
    private PersonalPane personal;
    private ManDBPane mandb;
    private DBPane db;
    private MkDBPane mkdb;
    private AddUserPane addusr;
    private MemPane mem;
    private JoinDBPane joindb;
    private PermPane perm;
    private Client client;
    private MainFrame current;

    /** Creates new form MainFrame */
    public MainFrame(Client client) {
        this.client = client;
        current = this;
        initComponents();
        login = new LoginPane(client, current);
        action = new GenActionPane(client, current);
        personal = new PersonalPane(client, current);
        mandb = new ManDBPane(client, current);
        db = new DBPane(client, current);
        mkdb = new MkDBPane(client, current);
        addusr = new AddUserPane(client, current);
        mem = new MemPane(client, current);
        joindb = new JoinDBPane(client,current);
        perm = new PermPane(client,current);
//        setSize(400,360);
//        getLoginPane();
    }

    public void getLoginPane() {
        MainPane.removeAll();
        MainPane.add(login);
        this.setTitle("dbDir Client - Login");
//        MainPane.validate();
//        MainPane.repaint();
//        this.setLocationRelativeTo(null);
        this.pack();
    }

    public void getActionPane() {
        MainPane.removeAll();
        MainPane.add(action);
        this.setTitle("dbDir Client - Action");
//        MainPane.validate();
//        MainPane.repaint();
//        this.setLocationRelativeTo(null);
        this.pack();
        action.init();
    }

    public void getPersonalPane() {
        MainPane.removeAll();
        MainPane.add(personal);
        this.setTitle("dbDir Client - Personal Profile");
//        MainPane.validate();
//        MainPane.repaint();
//        this.setLocationRelativeTo(null);
        this.pack();
        personal.init();
    }

    public void getAddUserPane() {
        MainPane.removeAll();
        MainPane.add(addusr);
        this.setTitle("dbDir Client - Register User");
//        MainPane.validate();
//        MainPane.repaint();
//        this.setLocationRelativeTo(null);
        this.pack();
    }

    public void getManDBPane() {
        MainPane.removeAll();
        MainPane.add(mandb);
        this.setTitle("dbDir Client - Manage DB Profile");
//        MainPane.validate();
//        MainPane.repaint();
//        this.setLocationRelativeTo(null);
        this.pack();
        mandb.init();
    }

    public void getDBPane() {
        MainPane.removeAll();
        MainPane.add(db);
        this.setTitle("dbDir Client - DB Profile");
//        MainPane.validate();
//        MainPane.repaint();
//        this.setLocationRelativeTo(null);
        this.pack();
        db.init();
    }

    public void getMkDBPane() {
        MainPane.removeAll();
        MainPane.add(mkdb);
        this.setTitle("dbDir Client - Make DB Profile");
//        MainPane.validate();
//        MainPane.repaint();
//        this.setLocationRelativeTo(null);
        this.pack();
    }

    public void getMemPane() {
        MainPane.removeAll();
        MainPane.add(mem);
        this.setTitle("dbDir Client - Members");
//        MainPane.validate();
//        MainPane.repaint();
//        this.setLocationRelativeTo(null);
        this.pack();
        mem.init();
    }

    public void getJoinDBPane() {
        MainPane.removeAll();
        MainPane.add(joindb);
        this.setTitle("dbDir Client - Join DB");
//        MainPane.validate();
//        MainPane.repaint();
//        this.setLocationRelativeTo(null);
        this.pack();
        joindb.init();
    }

    public void getPermPane() {
        MainPane.removeAll();
        MainPane.add(perm);
        this.setTitle("dbDir Client - Permission");
//        MainPane.validate();
//        MainPane.repaint();
//        this.setLocationRelativeTo(null);
        this.pack();
        perm.init();
    }

    public MainFrame getCurrent() {
        return current;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        MainPane = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("dbDir Client");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        MainPane.setLayout(new java.awt.BorderLayout());
        getContentPane().add(MainPane, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        client.doExit();
    }//GEN-LAST:event_formWindowClosing
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                MainFrame frame = new MainFrame();
//                frame.setVisible(true);
//                frame.setLocationRelativeTo(null);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel MainPane;
    // End of variables declaration//GEN-END:variables
}
